package com.wc.AlgoOJ_homework.ALOJ模块测试Ⅱ.F_背包与魔法;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @Author congge
 * @Date 2024/5/16 15:17
 * @description http://43.138.190.70:8888/p/564?tid=663e2cd8d39d10926ed3fa74
 */
public class Main {
    static FastReader sc = new FastReader();
    static PrintWriter out = new PrintWriter(System.out);
    static int N = 2010, M = 10010;
    // f[i][j] 表示前面i件物品是否使用了j = 1使用了, j = 0没使用
    static int[][] f = new int[M][2];
    static int n, m, k;

    public static void main(String[] args) {
        n = sc.nextInt();
        m = sc.nextInt();
        k = sc.nextInt();
        for (int i = 1; i <= n; i++) {
            int w = sc.nextInt(), v = sc.nextInt();
            for (int j = m; j >= w; j--) {
                f[j][0] = Math.max(f[j][0], f[j - w][0] + v);
                f[j][1] = Math.max(f[j][1], f[j - w][1] + v);
                if (j >= w + k) {
                    f[j][1] = Math.max(f[j][1], f[j - w - k][0] + v * 2);
                }
            }
        }
        out.println(Math.max(f[m][1], f[m][0]));
        out.flush();
    }
}

class FastReader {
    StringTokenizer st;
    BufferedReader br;

    FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    String nextLine() {
        String s = "";
        try {
            s = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return s;
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    // 是否由下一个
    boolean hasNext() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                String line = br.readLine();
                if (line == null)
                    return false;
                st = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
}
